<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bindAll</title>
</head>

<body>
    <div>点击页面然后打开控制台查看打印结果</div>
    <script>

        const bindAll = (obj, ...handlers) =>
            handlers.forEach(
                handler => (
                    (h = obj[handler]),
                    (obj[handler] = function () {
                        return h.apply(obj);
                    })
                )
            );

        const view = {
            label: 'docs',
            click: function () {
                console.log('clicked ' + this.label);
            }
        };
        bindAll(view, 'click');
        document.addEventListener('click', view.click);
    </script>
</body>

</html>